package com.wetao.lib_common.greendao.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.wetao.lib_common.greendao.model.ExamListen;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "EXAM_LISTEN".
*/
public class ExamListenDao extends AbstractDao<ExamListen, Long> {

    public static final String TABLENAME = "EXAM_LISTEN";

    /**
     * Properties of entity ExamListen.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property ListeningUrl = new Property(1, String.class, "listeningUrl", false, "LISTENING_URL");
        public final static Property Duration = new Property(2, Integer.class, "duration", false, "DURATION");
        public final static Property QuesitonIdArr = new Property(3, String.class, "quesitonIdArr", false, "QUESITON_ID_ARR");
        public final static Property AssistantExamId = new Property(4, Long.class, "assistantExamId", false, "ASSISTANT_EXAM_ID");
    }

    private Query<ExamListen> assistantExam_ListenListQuery;

    public ExamListenDao(DaoConfig config) {
        super(config);
    }
    
    public ExamListenDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"EXAM_LISTEN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"LISTENING_URL\" TEXT," + // 1: listeningUrl
                "\"DURATION\" INTEGER," + // 2: duration
                "\"QUESITON_ID_ARR\" TEXT," + // 3: quesitonIdArr
                "\"ASSISTANT_EXAM_ID\" INTEGER NOT NULL );"); // 4: assistantExamId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"EXAM_LISTEN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, ExamListen entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String listeningUrl = entity.getListeningUrl();
        if (listeningUrl != null) {
            stmt.bindString(2, listeningUrl);
        }
 
        Integer duration = entity.getDuration();
        if (duration != null) {
            stmt.bindLong(3, duration);
        }
 
        String quesitonIdArr = entity.getQuesitonIdArr();
        if (quesitonIdArr != null) {
            stmt.bindString(4, quesitonIdArr);
        }
        stmt.bindLong(5, entity.getAssistantExamId());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, ExamListen entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String listeningUrl = entity.getListeningUrl();
        if (listeningUrl != null) {
            stmt.bindString(2, listeningUrl);
        }
 
        Integer duration = entity.getDuration();
        if (duration != null) {
            stmt.bindLong(3, duration);
        }
 
        String quesitonIdArr = entity.getQuesitonIdArr();
        if (quesitonIdArr != null) {
            stmt.bindString(4, quesitonIdArr);
        }
        stmt.bindLong(5, entity.getAssistantExamId());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public ExamListen readEntity(Cursor cursor, int offset) {
        ExamListen entity = new ExamListen( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // listeningUrl
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // duration
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // quesitonIdArr
            cursor.getLong(offset + 4) // assistantExamId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, ExamListen entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setListeningUrl(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setDuration(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setQuesitonIdArr(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setAssistantExamId(cursor.getLong(offset + 4));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(ExamListen entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(ExamListen entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(ExamListen entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "listenList" to-many relationship of AssistantExam. */
    public List<ExamListen> _queryAssistantExam_ListenList(Long assistantExamId) {
        synchronized (this) {
            if (assistantExam_ListenListQuery == null) {
                QueryBuilder<ExamListen> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.AssistantExamId.eq(null));
                assistantExam_ListenListQuery = queryBuilder.build();
            }
        }
        Query<ExamListen> query = assistantExam_ListenListQuery.forCurrentThread();
        query.setParameter(0, assistantExamId);
        return query.list();
    }

}
